/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.isip.transformation.difference;

import com.isip.transformation.Transformation;

/**
 *
 * @author Fauzan
 */
public class SimpleDifference implements Transformation{

    @Override
    public int[][] doTransform(int[][] matrix) {
        int[][] new_matrix = new int[matrix.length][matrix[0].length];
        
        for(int i =0; i < matrix.length; i++ ) {
            for(int j=0; j < matrix[i].length; j++) {
                int n = matrix[i][j];
                int max = 0;
                
                if(i > 0 && j > 0) {
                    if(max < (matrix[i-1][j-1]-n))
                        max = matrix[i-1][j-1]-n;
                }
                
                if(i > 0) {
                    if(max < matrix[i-1][j]-n) {
                        max = matrix[i-1][j]-n;
                    }
                }
                
                if(i > 0 && j < matrix[i].length-1) {
                    if(max < matrix[i-1][j+1]-n) {
                        max = matrix[i-1][j+1]-n;
                    }
                }
                
                 if(j < matrix[i].length-1) {
                    if(max < matrix[i][j+1]-n) {
                        max = matrix[i][j+1]-n;
                    }
                }
                 
                
                if(i < matrix.length-1 && j < matrix[i].length-1) {
                    if(max < matrix[i+1][j + 1]-n) {
                        max = matrix[i+1][j + 1]-n;
                    }
                }
                
                if(i < matrix.length-1) {
                    if(max < matrix[i+1][j]-n) {
                        max = matrix[i+1][j]-n;
                    }
                }
                
                if(i < matrix.length-1 && j > 0) {
                    if(max < matrix[i+1][j-1]-n) {
                        max = matrix[i+1][j-1]-n;
                    }
                }
                
                if(j > 0) {
                    if(max < matrix[i][j-1]-n) {
                        max = matrix[i][j-1]-n;
                    }
                }
                
                new_matrix[i][j] = max;
                
            }
        }
        
        return new_matrix;
    }
    
}
